static KeyValuePair <MemberInfo, object[]> _GetInstanceData(CodeTypeReference tr)
        {
            if (0 < tr.ArrayRank && null != tr.ArrayElementType && 0 == (int)tr.Options && 0 == tr.TypeArguments.Count)
            {
                return(new KeyValuePair <MemberInfo, object[]>(
                           tr.GetType().GetConstructor(new Type[] { typeof(CodeTypeReference), typeof(int) }),
                           new object[] { tr.ArrayElementType, tr.ArrayRank }));
            }

            if (0 != (int)tr.Options)
            {
                if (0 == tr.TypeArguments.Count)
                {
                    return(new KeyValuePair <MemberInfo, object[]>(
                               tr.GetType().GetConstructor(new Type[] { typeof(string), typeof(CodeTypeReferenceOptions) }),
                               new object[] { tr.BaseType, tr.Options }));
                }
            }
            else
            {
                if (0 == tr.TypeArguments.Count)
                {
                    var t = Type.GetType(tr.BaseType, false, false);
                    if (null == t)
                    {
                        return(new KeyValuePair <MemberInfo, object[]>(
                                   tr.GetType().GetConstructor(new Type[] { typeof(string) }),
                                   new object[] { tr.BaseType }));
                    }
                    return(new KeyValuePair <MemberInfo, object[]>(
                               tr.GetType().GetConstructor(new Type[] { typeof(Type) }),
                               new object[] { t }));
                }
                else
                {
                    return(new KeyValuePair <MemberInfo, object[]>(
                               tr.GetType().GetConstructor(new Type[] { typeof(string), typeof(CodeTypeReference[]) }),
                               new object[] { tr.BaseType, _ToArray(tr.TypeArguments) }));
                }
            }
            return(new KeyValuePair <MemberInfo, object[]>(typeof(CodeDomBuilder).GetMethod("TypeReference"),
                                                           new object[] { tr.BaseType, tr.Options, _ToArray(tr.TypeArguments), tr.ArrayElementType, tr.ArrayRank }));
        }
Exemplo n.º 2
0
        public void SetTypeReferenceAsInterface(CodeTypeReference typeReference)
        {
            // this hack is necessary for VB.NET code generation
            if (TargetLanguage == CodeDomProviderLanguage.VB)
            {
                var typeReferenceType = typeReference.GetType();
                var isInterfaceField  = typeReferenceType.GetField("_isInterface", BindingFlags.Instance | BindingFlags.NonPublic);
                if (isInterfaceField == null)
                {
                    throw new InvalidOperationException("CodeDom version does not support VB.NET generation.");
                }

                isInterfaceField.SetValue(typeReference, true);
            }
        }