private IFudgeSerializationSurrogate BuildSurrogate(Type type, FudgeSurrogateAttribute attrib) { var surrogateType = attrib.SurrogateType; var constructor = surrogateType.GetConstructor(new Type[] { typeof(FudgeContext), typeof(Type) }); object[] args; if (constructor != null) { args = new object[] { context, type }; } else if ((constructor = surrogateType.GetConstructor(new Type[] { typeof(Type) })) != null) { args = new object[] { type }; } else if ((constructor = surrogateType.GetConstructor(Type.EmptyTypes)) != null) { args = new object[] { }; } else { Debug.Assert(false, "Lack of suitable constructor should have been picked up by FudgeSurrogateAttribute"); throw new FudgeRuntimeException("Surrogate type " + surrogateType + " does not have appropriate constructor"); } return((IFudgeSerializationSurrogate)constructor.Invoke(args)); }
private IFudgeSerializationSurrogate BuildSurrogate(Type type, FudgeSurrogateAttribute attrib) { var surrogateType = attrib.SurrogateType; var constructor = surrogateType.GetConstructor(new Type[] { typeof(FudgeContext), typeof(Type) }); object[] args; if (constructor != null) { args = new object[] { context, type }; } else if ((constructor = surrogateType.GetConstructor(new Type[] { typeof(Type) })) != null) { args = new object[] { type }; } else if ((constructor = surrogateType.GetConstructor(Type.EmptyTypes)) != null) { args = new object[] { }; } else { Debug.Assert(false, "Lack of suitable constructor should have been picked up by FudgeSurrogateAttribute"); throw new FudgeRuntimeException("Surrogate type " + surrogateType + " does not have appropriate constructor"); } return (IFudgeSerializationSurrogate)constructor.Invoke(args); }